<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Session;
class Login extends Controller
{
    public function index()
    {
//        $admin=Db::table('admin')->select();
//        dump($admin);

        return $this->fetch();
    }

    public function checkLogin()
    {
        $adminname=input('adminname');
        $password=input('password');
        $admin=Db::table('admin')->where('adminname',$adminname)->find();
        // dump($admin);
        if ($admin){
            if ($admin['password']==md5($password)){
                Session::set('admin',$admin);
                return $this->redirect('index/index');
            }
            else{
                echo"<script>alert('密码错误')</script>";
                return $this->redirect('login/index');
            }
        }
        else{
            echo"<script>alert('用户名不存在')</script>";
            return $this->redirect('login/index');

        }
    }
}